package com.business.controller;

import com.business.api.UserApi;
import com.comm.config.TopicRabbitConfig;
import com.comm.entity.po.LoginUserInfo;
import com.comm.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/7/20
 *
 **/
@RestController
@RequestMapping("/business")
@Api("用户操作控制器")
@Slf4j
public class UserController {

    @Autowired
    private UserApi userApi;

    @Value("${spring.application.name}")
    private String businessName;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/toLogin")
    @ApiOperation("用户登录操作")
    ResponseResult<LoginUserInfo> userLoginVerify(@RequestBody LoginUserInfo loginUserInfo){
        log.info("用户登录通过网关来到了business服务....");
        return userApi.userLoginVerify(loginUserInfo);
    }

    @GetMapping("/sendRabbitMessage")
    public ResponseResult<Object> sendRabbitMessage(){
        ResponseResult<Object> result = new ResponseResult<>("1000","business provider message",
                "生产者服务 I am "+businessName+" service,hello stranger server !!!");
        rabbitTemplate.convertAndSend(TopicRabbitConfig.BUSINESS_TOPIC_EXCHANGE_NAME,TopicRabbitConfig.BUSINESS_TOPIC_KEY,result);
        return ResponseResult.isSuccess("business server data send success ...");
    }

}
